﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Board1.Resources;
using Board1.Info;
using Board1.GetData;

namespace Board1
{
    public partial class MainPage : PhoneApplicationPage
    {
        public static SongData SongSelected;
        public static int indexSongSelected;

        public static AlbumData AlbumSelected;
        public static int indexAlbumSelected;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            //DataContext = App.listHot100;
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        //data cho listbox

        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
            base.OnNavigatedTo(e);
            hot100.DataContext = App.listHot100;
            top200.DataContext = App.listTop200;
            //DataContext = ;
        }

        // bat su kien khi click item trong danh sach bai hat
        private void listsong_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem selected = this.listSong.ItemContainerGenerator.ContainerFromIndex(this.listSong.SelectedIndex) as ListBoxItem;
            indexSongSelected = this.listSong.SelectedIndex;
            SongSelected = selected.DataContext as SongData;
            this.NavigationService.Navigate(new Uri("/UIPage/SongPage.xaml", UriKind.Relative));
        }

        // bat su kien khi click item trong danh sach album
        private void listAlbum_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem selected = this.listAlbum.ItemContainerGenerator.ContainerFromIndex(this.listAlbum.SelectedIndex) as ListBoxItem;
            indexAlbumSelected = this.listAlbum.SelectedIndex;
            AlbumSelected = selected.DataContext as AlbumData;
            this.NavigationService.Navigate(new Uri("/UIPage/AlbumPage.xaml", UriKind.Relative));
        }
        
    }
}